package com.suliao.home.serviceImpl.industry;

import com.suliao.home.entity.industry.ExhibitTypeDO;
import com.suliao.home.mapper.industry.ExhibitMapper;
import com.suliao.home.mapper.industry.ExhibitTypeMapper;
import com.suliao.home.service.industry.ExhibitTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author： M1nG-CodeGenerator
 * @since： 2020-12-14 16:10:11
 * @description： 展品类别 服务实现类
 * @version： 1.0
 */
@Service
public class ExhibitTypeServiceImpl extends ServiceImpl<ExhibitTypeMapper, ExhibitTypeDO> implements ExhibitTypeService {

    @Autowired
    private ExhibitTypeMapper exhibitTypeMapper;

    @Autowired
    private ExhibitMapper exhibitMapper;

    /**
     * 获取展品一级类型
     * @return
     */
    @Override
    public List<ExhibitTypeDO> getClassificationType(Integer companyId) {
        List<ExhibitTypeDO> firstLevelList =exhibitTypeMapper.getClassificationType(companyId);
        List<ExhibitTypeDO> resLevelList = new ArrayList<>();
        if (firstLevelList.size()>0){
            for (int i = 0; i <firstLevelList.size() ; i++) {
                Integer id = firstLevelList.get(i).getId();
                //通过一级分类的uuid去查询该一级分类下展品的个数，若数量大于1，则显示，否则不显示
                Integer productNum = exhibitMapper.getProductNumById(id);
                if (productNum>0){
                    resLevelList.add(firstLevelList.get(i));
                    if (resLevelList.size()>=4){
                        break;
                    }
                }
            }
        }
        return resLevelList;
    }
}
